<?php
include("../common.inc.php");
InitGP(array("page","action","eid","delids","pagesize","state")); //初始化变量全局返回
include("function_common.php");
//初始化对象
include(INC_PATH."/mail.class.php");
$mail=new MailClass();
include_once(INC_PATH."/city.class.php");
$city=new CityClass();
if(empty($action)){
	InitGP(array("email","tid")); //初始化变量全局返回
	if(!empty($email))$wherestr[]="email like '%{$email}%'";
	if(!empty($state))$wherestr[]="state in({$state})";else $wherestr[]="state in(1)";

	if(!empty($wherestr)) $wheresql = implode(' AND ', $wherestr);	//条件汇总
	
	$pagesize = !empty($pagesize) ? $pagesize : 15; //一页显示信息数
	//获取当前页码
	$total=$mail->getcount($wheresql); 							  //总信息数
	$page = isset($page) ? max(1, intval($page)) : 1;             //处理页码变量
	$offset=($page-1)*$pagesize;   								  //偏移量
	$dataarray=$mail->getdata("$offset,$pagesize",$wheresql); //获取团购数据
	
	//包含后台模板文件
	include("tpl/email_list.htm");
}elseif ($action=="lose") {
		//更新状态禁用这次返利
	InitGP(array("eid")); //初始化变量全局返回
	if(GetNum($eid)){
	$mail->state($eid,2);
	showmsg("设置失效状态成功!","email_list.php");//成功
	}else showmsg("缺少参数 操作失败!","email_list.php");//失败
}elseif ($action=="check") {
		//更新状态禁用或者启用
	InitGP(array("eid")); //初始化变量全局返回
	if(GetNum($eid)){
		//执行返利操作
		$info=$mail->state($eid,1);
		if($info)showmsg("恢复正常状态成功!","email_list.php");//成功
		else showmsg("操作失败!","email_list.php");//失败
	}else showmsg("缺少参数 操作失败!","email_list.php");//失败
	
}elseif ($action=="del" && !empty($eid)){
	//执行删除操作
	$eid=GetNum($eid);
	$info=$mail->del($eid);
	if($info=="OK")showmsg("删除email成功！","email_list.php");
	else showmsg($info,"email_list.php");
}elseif ($action=="dels"){
	if(empty($delids)){showmsg("没有选择任何对象！","email_list.php");exit;}//空选择
	//执行删除多个操作
	foreach ($delids as $id){
		$id=GetNum($id);
		$info=$mail->del($id);
	}
	if($info=="OK")showmsg("删除email成功！","email_list.php");
	else showmsg($info,"email_list.php");
}elseif($action=="downxls"){

	//获取当前页码
	$total=$mail->getcount(); 							  //总信息数
	$dataarray=$mail->getdata(); //获取团购数据

	$keynames=array(
	"eid"=>"編號",
	"email"=>"電子郵箱",
	"uid"=>"用戶ID",
	"cityid"=>"城市ID",
	"addtime"=>"添加時間",
	"state"=>"狀態"
	);
	down_xls($dataarray, $keynames,'dataxls_'.$total);
}elseif($action=="downtxt"){
	$total=$mail->getcount(); 							  //总信息数
	$dataarray=$mail->getdata();
	$num=1;
	foreach($dataarray as $k=>$value){
		$txt[] = $value['email'];
//		if($num/2==5){
//				echo "test";
//				$txt = join("\n", $txt);
//				header('Content-Disposition: attachment; filename="'.date('Y-m-dHis').'userlist.txt"');
//				$txt = "";
//		}
		$num++;
	}
	$txt = join("\n", $txt);
	header('Content-Disposition: attachment; filename="user.txt"');
	die(iconv(CHARSET,'UTF-8',$txt));
}

?>

